define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

	if(params.father_id!='undefined'){
		httpService.post(app.urls.menu_select,{"id":params.father_id},function(data){
			if("0000" === data.code){
				$scope.menu_name = data.data[0].name;
				$scope.findButton(data.data[0].id);
			}else{
				alert(data.msg);
			}
		});
	}else {
		$scope.form.sheet=params.sheet;
		$scope.form.field=params.field;
		$scope.form.type=params.type;
	}
	$scope.findButton=function(menu_id){
		httpService.post(app.urls.button_select,{"menu_id":menu_id},function(data){
			if("0000" === data.code){
				$scope.buttons = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	
	
	//查询家长列表
	$scope.find = function(){
		httpService.postpage(app.urls.company_select,$scope.form,function(data){
			if("0000" === data.code){
    			$scope.rows = data.data;
    			console.log($scope.rows)
    		}else{
    			alert(data.msg);
    		}
		});
	}
	
	
	$scope.findstu = function(row){
		 eventBusService.publish("modal.page","modules/content/usermanagement/company/info?id="+row.id);
	}
	
	
	//按钮点击事件-条件查询
	$scope.select = function(){
    	$scope.page.current = 1;
    	$scope.find();
    }
	httpService.post(app.urls.role_selectType,{},function(data){
		if("0000" === data.code){
			$scope.form.userrole = data.data[0].type;
			$scope.find();
		}else{
			alert(data.msg);
		}
	});
	$scope.clickBtn=function(event){
		var menu = {};
		if(event=='add'){
			menu.url = "modules/content/usermanagement/company/add?fk_menuid="+params.fk_menuid+ "&father_id=" + params.father_id;
			if(params.father_id!='undefined'){
				eventBusService.publish("modules.content.load",menu);
			}else {
				eventBusService.publish("modules.content.load",menu);
			}
		}
		if(event=='update'){
			var values = [];
			$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
				values.push($(this).val());
			});
			if(values.length < 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
			}else if(values.length > 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"您选择了多行数据，请重新选择。"});
			}else {
				menu.url = "modules/content/usermanagement/company/update?id=" + values[0] + "&father_id=" + params.father_id;
				if(params.father_id!='undefined'){
					eventBusService.publish("modules.content.load",menu);
				}else {
					eventBusService.publish("modules.content.load",menu);
				}
			}
		}
		if(event=='delete'){
			var values = [];
			var ids="";
			$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
				var arr=$(this).val().split(',');
				values.push(arr[0]);
				ids = ids+",'"+arr[0]+"'";
			});
			if(values.length < 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
			}else{
				eventBusService.publish("modal.alert",{"content":"你是否确认删除这"+values.length+"数据？","isAutoClose":false,"confirm":function(){
						httpService.post(app.urls.user_delete,{"id":ids.replace(',','')},function(data){
							if("0000" === data.code){
								httpService.post(app.urls.company_delete,{"id":ids.replace(',','')}, function(data) {
									if ("0000" === data.code) {
										$scope.select();
									} else {
										alert(data.msg);
									}
								});
							}else{
								alert(data.msg);
							}
						});
					},"cancel":function(){
						//用户取消，不做操作
					}});
			}
		}
		/*if(event=='export'){
			var values = [];
			$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
				values.push($(this).val());
			});
			$scope.form.list = JSON.stringify(values);
			httpService.post(app.urls.student_export,$scope.form, function(data) {
				if ("0000" === data.code) {
					window.location.href = data.data;
				} else {
					alert(data.msg);
				}
			});
		}
		if(event=='template'){
			httpService.post(app.urls.student_template,{}, function(data) {
				if ("0000" === data.code) {
					window.location.href = data.data;
				} else {
					alert(data.msg);
				}
			});
		}
		if(event=='import'){
			eventBusService.publish("modal.page","modules/content/usermanagement/student/import");
		}*/
	}
	//返回
	$scope.goback = function(){
		var menu = {"url": "modules/content/welcome/school"};
		eventBusService.publish("modules.content.load", menu);
	}
	//接收数据刷新
	eventBusService.subscribe('content.page.reload', function(event,data) {
		$scope.select();
	});
}}});